<template>
  <div>
    <table>
      <tr>
        <td>用户名</td>
        <td><input type="text" v-model="username" placeholder="请输入用户名"></td>
      </tr>
      <tr>
        <td>密码</td>
        <td><input type="text" v-model="password" placeholder="请输入密码"></td>
      </tr>
      <tr>
        <td></td>
        <td>
          <Button @click="login" color="blue">登录</Button>
          <Button @click="set" color="blue">重置</Button>
        </td>
      </tr>
    </table>
  </div>
</template>

<script>
    export default {
        name: "login",
      data:function () {
        return{
          username: '',
          password:'',
        }
      },

      methods:{
          login:function () {
            this.axios({
              url:'http://127.0.0.1:8000/login/',
              method:'get',
              params:{username:this.username, password:this.password},
            }).then(res=>{
              if(res.data.code===200){
                alert(res.data.message);
                sessionStorage.setItem('uid', res.data.uid);
                sessionStorage.setItem('uname', res.data.username);
              }else {
                alert(res.data.message);
              }
            })
          },

          set:function () {
            this.username='';
            this.password='';
          }
      }
    }
</script>

<style scoped>

</style>
